package com.cskaoyan.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.SaleAttributeInfoDTO;
import com.cskaoyan.mall.product.dto.SpuInfoPageDTO;
import com.cskaoyan.mall.product.model.SpuInfo;
import com.cskaoyan.mall.product.query.SpuInfoParam;
import com.cskaoyan.mall.product.service.SalesAttributeService;
import com.cskaoyan.mall.product.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/7/1 17:35
 */
@RestController
public class AdminSpuController {

    @Autowired
    SalesAttributeService salesAttributeService;
    @Autowired
    SpuService spuService;

    //1. 查询所有的销售属性
    @GetMapping("admin/product/baseSaleAttrList")
    public Result SaleAttrList(){

        List<SaleAttributeInfoDTO> saleAttrInfoList = salesAttributeService.getSaleAttrInfoList();
        return Result.ok(saleAttrInfoList);
    }

    //2. 根据分页参数查询spu列表数据
    @GetMapping("admin/product/{page}/{size}")
    public Result getSpuInfoPage(@PathVariable Long page, @PathVariable Long size, Long category3Id){

        //2.1 根据分页参数获取分页参数对象
        Page<SpuInfo> pageParm = new Page<>(page, size);
        //2.2 查询spu列表数据
        SpuInfoPageDTO spuInfoPage = spuService.getSpuInfoPage(pageParm, category3Id);

        return Result.ok(spuInfoPage);
    }

    //3. 实现SPU的保存
    @PostMapping("admin/product/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoParam spuInfoParam){

        spuService.saveSpuInfo(spuInfoParam);
        return Result.ok();
    }
}
